<?php
namespace app\app\controller;

use app\common\controller\App;
use think\Db;
use think\Exception;


class Login extends App
{


    public function login()
    {
        $username = request()->param("username");
        $password = request()->param("password");
        if (empty($username)) {
            return $this->fail('请输入用户名');
        }
        if (empty($password)) {
            return $this->fail('请输入密码');
        }
        try {
            $result = model("Member")->login($username, $password);
        } catch (Exception $e) {
            return $this->fail($e->getMessage());
        }

        return $this->ok('登陆成功', $result);

    }

    public function register() {

        $username = request()->param('username');
        $password = request()->param('password');

        try{
            $result= model("Member")->register($username,$password);
        }catch (Exception $e){
            return $this->fail($e->getMessage());
        }

        if ($result){
            return $this->ok('注册成功');
        }else{
            return $this->fail('注册失败');
        }

    }




}
